package com.itheima.mall.controller.omsController;

import com.itheima.PageResult;
import com.itheima.dto.OrderDto;
import com.itheima.mall.service.omsService.OmsOrderService;
import com.itheima.pojo.oms.OmsOrder;
import com.itheima.vo.OmsOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OmsOrderController {
    @Autowired
    private OmsOrderService omsOrderService;

    //订单分页
    @GetMapping("/list")
    public ResponseEntity<PageResult<OmsOrder>> page(OrderDto orderDto, Integer pageNum,
                                                     Integer pageSize) {
        PageResult<OmsOrder> pageResult = omsOrderService.page(orderDto, pageNum, pageSize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 批量删除
     * @return
     */
    @PostMapping("/delete")
    public ResponseEntity delete(@RequestParam Integer[] ids){
            omsOrderService.deleteByIds(ids);
        return ResponseEntity.ok(null);
    }    /**
     * 批量关闭
     * @return
     */
    @PostMapping("/update/close")
    public ResponseEntity update(@RequestParam(value = "ids") Integer[] ids,@RequestParam(value = "note") String note ){

            omsOrderService.close(ids,note);
        return ResponseEntity.ok(null);
    }
    //批量发货
    @PostMapping("/update/delivery")
    public ResponseEntity updateDelivery(@RequestBody List<Map<String,String>> list){
        omsOrderService.delivery(list);
        return ResponseEntity.ok(null);
    }

    /**
     * 获取订单详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity<OmsOrderVo> findById(@PathVariable Integer id){

     OmsOrderVo omsOrderVo = omsOrderService.findById(id);
     return ResponseEntity.ok(omsOrderVo);
    }

    /**
     * 修改订单费用信息
     * @param map
     * @return
     */
    @PostMapping("/update/moneyInfo")
    public ResponseEntity updateMoneyInfo(@RequestBody Map<String,Object> map){
        omsOrderService.updateMony(map);
        return ResponseEntity.ok(null);
    }
    /**
     * 备注订单
     */
    @PostMapping("/update/note")
    public ResponseEntity updateNote(@RequestParam Long id,@RequestParam String note,@RequestParam Integer status){
        omsOrderService.updateNote(id,note,status);
        return ResponseEntity.ok(null);
    }



    /**
     * 修改收货人信息
     * @param map
     * @return
     */
    @PostMapping("/update/receiverInfo")
    public ResponseEntity updateReceiverInfo(@RequestBody Map<String,String> map){
        omsOrderService.updateReceiver(map);
        return ResponseEntity.ok(null);
    }

}
